package com.publishproject.test;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.RelativeLayout;

import com.ui_componet.popupwindow.BaseListPopupWindow;
import com.ui_componet.popupwindow.BasePopupObj;
import com.ui_componet.popupwindow.PopupBuilder;
import com.publishproject.R;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import rx.Observable;
import rx.Subscription;
import rx.functions.Action1;

public class BasePopActivity extends Activity {

    private Button button;
    private int count;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base_pop);
        button = (Button)findViewById(R.id.button);
        Subscription sub = Observable.interval(1, 1, TimeUnit.SECONDS)
                .subscribe(new Action1<Long>() {
                    @Override
                    public void call(Long aLong) {
                        Log.i("TAG", "sdfsf");
                        if (count >= 10){
                            throw new RuntimeException("abc");
                        }
                        count++;
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        Log.i("TAg","异常腿粗");
                    }
                });
    }
    public void onClick(View view){
        List<BasePopupObj> list = new ArrayList<>();
        list.add(new BasePopupObj("sdfds"));
        list.add(new BasePopupObj("12323"));
        list.add(new BasePopupObj("1232232323"));
        list.add(new BasePopupObj("1233424223"));
        BaseListPopupWindow baseListPopupWindow = new BaseListPopupWindow(this);
        baseListPopupWindow.addList(list);
        baseListPopupWindow.setWidth(WindowManager.LayoutParams.MATCH_PARENT);
//        baseListPopupWindow.setListviewParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
//                ViewGroup.LayoutParams.WRAP_CONTENT));
        baseListPopupWindow.setPosition(BaseListPopupWindow.Position.TOP);
        baseListPopupWindow.setPopupBuilder(new PopupBuilder()
        .checkedColor(getResources().getColor(R.color.green))
        .checkedDrawble(R.drawable.all_arrow)
                .checkedBackground(new ColorDrawable(getResources().getColor(R.color.color_eeeeee)))
                .background(new ColorDrawable(getResources().getColor(R.color.color_ff4966)))

        .color(getResources().getColor(R.color.color_cccccc))
        .size(15));
        int height = button.getMeasuredHeight();
        Log.i("TAG",height+"");
        int [] location = new int[2];
        button.getLocationInWindow(location);
        Log.i("TAG",location[0]+"---"+location[1]);
//        baseListPopupWindow.showAsDropDown();
        baseListPopupWindow.showAtLocation(button,Gravity.NO_GRAVITY,100,200);
    }
}
